package com.codermn.day715;

/**
 * @author jxau_scf
 * @date 2021/7/15 - 19:08
 */
public class SingleTon {
    public int count;
    private static SingleTon instance;
    private SingleTon(int n) {
        this.count=n;
    }

    public static SingleTon getInstance() {
        //不为空则直接返回instance
        if (instance!=null){
//            instance=new SingleTon(10);
            return instance;
        }
        //执行到这里，则说明instance为空，则需要new SingleTon,然后返回
        instance=new SingleTon(10);
        return instance;
    }
    public int getCount(){
        return this.count;
    }
}
class SingleTonTest{
    public static void main(String[] args) {
        SingleTon s1=SingleTon.getInstance();
        SingleTon s2=SingleTon.getInstance();
        //System.out.println(s1==s2);
        System.out.println(s1.getCount());


    }
}
